package ysq.xyg.host.model.po;

import cn.hutool.core.util.StrUtil;
import lombok.NoArgsConstructor;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.util.BaseUtil;
import ysq.xyg.sys.model.po.SysUser;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

/**
 * 房产-通知公告实体类
 *
 * @author congcong tao
 * @date 2019-12-11 15:08:31
 */
@Data
@NoArgsConstructor
@Table(name = "xyg_host_notice")
public class HostNotice implements Serializable{

	/**
     * 主键
     */ 
	@Id
	private String id;

	/**
     * 应用主键
     */ 
	@Column(name = "account_id")
	private String accountId;

	/**
	 * 是否选择城市1不选择2选择
	 */
	@Column(name = "is_city")
	private String isCity;

	/**
     * 城市主键,如果不设置即为全部
     */ 
	@Column(name = "city_id")
	private String cityId;

	/**
     * 是否推荐1=否2=是
     */ 
	@Column(name = "is_recommend")
	private String isRecommend;

	/**
     * 名称
     */ 
	@Column(name = "name")
	private String name;

	/**
	 * 分类
	 */
	@Column(name = "type_id")
	private String typeId;

	/**
     * 简介
     */ 
	@Column(name = "description")
	private String description;

	/**
     * 内容
     */ 
	@Column(name = "content")
	private String content;

	/**
     * 封面图片
     */ 
	@Column(name = "cover_image")
	private String coverImage;

	/**
     * 多图片
     */ 
	@Column(name = "images")
	private String images;

	/**
     * 类型
     */ 
	@Column(name = "type")
	private String type;

	/**
	 * 资讯来源
	 */
	@Column(name = "source_type")
	private String sourceType;

	/**
	 * 阅读次数
	 */
	@Column(name = "num")
	private Integer num;

	/**
     * 排序
     */ 
	@Column(name = "order_num")
	private Integer orderNum;

	/**
     * 创建者
     */ 
	@Column(name = "create_user")
	private String createUser;

	/**
     * 更新者
     */ 
	@Column(name = "update_user")
	private String updateUser;

	/**
     * 删除状态1、未删除2、已删除
     */ 
	@Column(name = "remove_tag")
	private String removeTag;

	/**
     * 创建时间
     */ 
	@Column(name = "create_time")
	private Date createTime;

	/**
     * 更新时间
     */ 
	@Column(name = "update_time")
	private Date updateTime;
	
	@Transient
	private String cityName;

	public String[] getImageList() {
		if (StringUtils.isEmpty(images)) {
			return new String[0];
		}
		return StrUtil.split(images, ",");
	}

	public HostNotice(SysUser sysUser) {
		this.id= BaseUtil.uId();
		this.accountId = sysUser.getAccountId();
		this.removeTag= BaseConstant.BASE_REMOVE_TAG_NORMAL;
		this.createTime = new Date();
		this.createUser = sysUser.getId();
		this.updateTime = new Date();
		this.updateUser = sysUser.getId();
	}
}